/*   1:    */ package com.rinsi.app.jczl.kjxx.tzry;
/*   2:    */ 
/*   3:    */ import com.rinsi.core.contoller.CoreSimpleController;
/*   4:    */ import com.rinsi.core.service.CoreSimpleService;
/*   5:    */ import com.rinsi.util.FileUtil;
/*   6:    */ import com.rinsi.util.FormaterUtil;
/*   7:    */ import com.rinsi.util.MapUtil;
/*   8:    */ import com.rinsi.util.SpringContextUtil;
/*   9:    */ import java.io.File;
/*  10:    */ import java.io.FileInputStream;
/*  11:    */ import java.io.IOException;
/*  12:    */ import java.io.PrintWriter;
/*  13:    */ import java.util.HashMap;
/*  14:    */ import java.util.Map;
/*  15:    */ import javax.servlet.ServletOutputStream;
/*  16:    */ import javax.servlet.http.HttpServletRequest;
/*  17:    */ import javax.servlet.http.HttpServletResponse;
/*  18:    */ import org.apache.poi.hssf.usermodel.HSSFCell;
/*  19:    */ import org.apache.poi.hssf.usermodel.HSSFRow;
/*  20:    */ import org.apache.poi.hssf.usermodel.HSSFSheet;
/*  21:    */ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/*  22:    */ import org.springframework.beans.factory.annotation.Autowired;
/*  23:    */ import org.springframework.stereotype.Controller;
/*  24:    */ import org.springframework.transaction.annotation.Transactional;
/*  25:    */ import org.springframework.ui.ModelMap;
/*  26:    */ import org.springframework.web.bind.annotation.RequestMapping;
/*  27:    */ import org.springframework.web.bind.annotation.RequestParam;
/*  28:    */ import org.springframework.web.multipart.MultipartFile;
/*  29:    */ 
/*  30:    */ @Controller
/*  31:    */ @RequestMapping({"/jczl/kjxx/tzry"})
/*  32:    */ public class TzryController
/*  33:    */   extends CoreSimpleController
/*  34:    */ {
/*  35:    */   @Autowired
/*  36:    */   private TzryService tzryService;
/*  37:    */   
/*  38:    */   @RequestMapping({"/upload"})
/*  39:    */   public void upload(@RequestParam MultipartFile file, HttpServletRequest request, HttpServletResponse response)
/*  40:    */   {
/*  41:    */     try
/*  42:    */     {
/*  43: 51 */       this.tzryService.uploadImage(request.getParameter("ID"), file.getBytes());
/*  44:    */       
/*  45: 53 */       response.setCharacterEncoding("UTF-8");
/*  46:    */       
/*  47: 55 */       response.getWriter().print(file.getOriginalFilename());
/*  48:    */     }
/*  49:    */     catch (Exception e)
/*  50:    */     {
/*  51: 59 */       e.printStackTrace();
/*  52:    */     }
/*  53:    */   }
/*  54:    */   
/*  55:    */   @RequestMapping({"/getImage"})
/*  56:    */   protected void getImage(ModelMap model, HttpServletRequest request, HttpServletResponse response)
/*  57:    */   {
/*  58:    */     try
/*  59:    */     {
/*  60: 72 */       Map<String, Object> data = this.tzryService.item(model);
/*  61:    */       
/*  62: 74 */       response.setContentType("image/JPEG;charset=UTF-8");
/*  63:    */       
/*  64: 76 */       response.setContentType("application/x-msdownload;");
/*  65:    */       
/*  66: 78 */       response.getOutputStream().write((byte[])MapUtil.getMapData(data, "data").get("TZZYRY_ZP"));
/*  67:    */     }
/*  68:    */     catch (IOException e)
/*  69:    */     {
/*  70: 82 */       e.printStackTrace();
/*  71:    */     }
/*  72:    */   }
/*  73:    */   
/*  74:    */   @RequestMapping({"/excelIn"})
/*  75:    */   @Transactional
/*  76:    */   public void execlIn(@RequestParam MultipartFile file, ModelMap model, HttpServletRequest request, HttpServletResponse response)
/*  77:    */   {
/*  78: 91 */     Integer rowNum = Integer.valueOf(0);
/*  79:    */     try
/*  80:    */     {
/*  81: 95 */       Map<String, Object> params = servce().getParams(model);
/*  82:    */       
/*  83: 97 */       String mod = request.getParameter("MODULE_NO") == null ? "" : request.getParameter("MODULE_NO");
/*  84:    */       
/*  85: 99 */       String filepath = (String)((Map)SpringContextUtil.getBean("config")).get("filepath") + mod + "/";
/*  86:    */       
/*  87:101 */       String config = (String)((Map)SpringContextUtil.getBean("execlConfig")).get(mod);
/*  88:    */       
/*  89:103 */       String ID = request.getParameter("ID") + "/";
/*  90:    */       
/*  91:105 */       params.put(request.getParameter("FIELD"), request.getParameter("ID"));
/*  92:    */       
/*  93:107 */       filepath = filepath + ID;
/*  94:    */       
/*  95:109 */       File impFile = FileUtil.createFile(filepath, file.getOriginalFilename(), file.getBytes());
/*  96:    */       
/*  97:111 */       HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(impFile));
/*  98:    */       
/*  99:113 */       HSSFSheet sheet = workbook.getSheetAt(0);
/* 100:    */       
/* 101:115 */       HSSFRow row = null;
/* 102:    */       
/* 103:117 */       HSSFCell cell = null;
/* 104:    */       
/* 105:119 */       int totalRow = sheet.getLastRowNum();
/* 106:    */       
/* 107:121 */       String[] cell_config = config.split(",");
/* 108:    */       
/* 109:123 */       int cell_size = cell_config.length;
/* 110:125 */       for (int i = 1; i <= totalRow; i++)
/* 111:    */       {
/* 112:127 */         rowNum = Integer.valueOf(sheet.getRow(i).getRowNum());
/* 113:    */         
/* 114:129 */         row = sheet.getRow(i);
/* 115:    */         
/* 116:131 */         Map<String, Object> pms = new HashMap();
/* 117:    */         
/* 118:133 */         pms.putAll(params);
/* 119:135 */         for (int j = 0; j < cell_size; j++)
/* 120:    */         {
/* 121:137 */           cell = row.getCell(j);
/* 122:    */           
/* 123:139 */           pms.put(cell_config[j], FormaterUtil.convertCell(cell));
/* 124:    */         }
/* 125:142 */         this.tzryService.importDatas(pms);
/* 126:    */       }
/* 127:145 */       response.setCharacterEncoding("UTF-8");
/* 128:    */       
/* 129:147 */       response.getWriter().print(file.getOriginalFilename());
/* 130:    */     }
/* 131:    */     catch (Exception e)
/* 132:    */     {
/* 133:151 */       e.printStackTrace();
/* 134:    */     }
/* 135:    */   }
/* 136:    */   
/* 137:    */   public CoreSimpleService servce()
/* 138:    */   {
/* 139:159 */     return this.tzryService;
/* 140:    */   }
/* 141:    */ }


/* Location:           D:\Users\Desktop\shanxi\项目\sxazmis\WEB-INF\classes\
 * Qualified Name:     com.rinsi.app.jczl.kjxx.tzry.TzryController
 * JD-Core Version:    0.7.0.1
 */